# Maintainer: AndyRTR <andyrtr@archlinux.org>

pkgbase=graphite
pkgname=(graphite graphite-docs)
pkgver=1.3.14
pkgrel=3
epoch=1
arch=('loong64' 'x86_64')
url="https://github.com/silnrsi/graphite"
pkgdesc='reimplementation of the SIL Graphite text processing engine'
license=('LGPL' 'GPL' 'custom')
depends=('gcc-libs')
makedepends=('cmake' 'freetype2' 'python'
             # for documentation
             'doxygen' 'dblatex' 'graphviz' 'asciidoc')
checkdepends=('python-fonttools')
# https://github.com/silnrsi/graphite/releases/download/1.3.14/graphite2-1.3.14.sha256sum
source=(https://github.com/silnrsi/graphite/releases/download/${pkgver}/graphite2-${pkgver}.tgz)
sha256sums=('f99d1c13aa5fa296898a181dff9b82fb25f6cc0933dbaa7a475d8109bd54209d')

build() {
  local cmake_options=(
    -DCMAKE_BUILD_TYPE=None
    -DCMAKE_INSTALL_PREFIX=/usr
    -DCMAKE_SKIP_INSTALL_RPATH=ON
    -DGRAPHITE2_COMPARE_RENDERER=OFF
    -DGRAPHITE2_VM_TYPE=direct
  )

  cmake -S graphite2-${pkgver} -B build "${cmake_options[@]}"
  cmake --build build
  cmake --build build -t docs -j1
}

check() {
  cd build
  ctest --output-on-failure --stop-on-failure -j$(nproc)
}

package_graphite() {
  optdepends=('graphite-docs: Documentation')
  provides=('libgraphite2.so')

  DESTDIR="$pkgdir" cmake --install build

  # licenses
  install -Dm644 graphite2-${pkgver}/COPYING -t "${pkgdir}/usr/share/licenses/${pkgname}"
}

package_graphite-docs() {
  pkgdesc+=" (documentation)"
  depends=()

  local docdir="${pkgdir}/usr/share/doc/${pkgbase}"
  mkdir -p "${docdir}/api"
  cp -vrf build/doc/doxygen/{html,latex/refman.pdf} "${docdir}/api"
  cp -vrf build/doc/{GTF,manual}.html "${docdir}"

  # licenses
  install -Dm644 graphite2-${pkgver}/COPYING -t "${pkgdir}/usr/share/licenses/${pkgname}"
}

# vim:set sw=2 sts=-1 et:
